/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
	<div>
		<div id="explanation" class="explanation" style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;">
			<div class="bckopa-tips">
				<div class="title">
					<img src="@/static/images/handd.png" alt />
					<h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
				</div>
				<ul>
					<li>网站全局基本设置，商城及其他模块相关内容在其各自栏目设置项内进行操作。</li>
				</ul>
			</div>
			<span title="收起提示" id="explanationZoom" style="display: block;"></span>
		</div>
		<el-form ref="form" :model="form" label-width="200px" label-position="right">
			<el-form-item label="邮件发送服务器(SMTP)">
				<el-input v-model="form.smtp_server" size="mini"></el-input>
				<p class="notic">发送邮箱的smtp地址。如: smtp.gmail.com或smtp.qq.com</p>
			</el-form-item>
			<el-form-item label="服务器(SMTP)端口 ">
				<el-input v-model="form.smtp_port" size="mini"></el-input>
				<p class="notic">smtp的端口。默认为25。具体请参看各STMP服务商的设置说明 （如果使用Gmail，请将端口设为465）</p>
			</el-form-item>
			<el-form-item label="邮箱账号">
				<el-input v-model="form.smtp_user" size="mini"></el-input>
				<p class="notic">使用发送邮件的邮箱账号</p>
			</el-form-item>
			<el-form-item label="邮箱密码/授权码 ">
				<el-input v-model="form.smtp_pwd" size="mini"></el-input>
				<p class="notic">使用发送邮件的邮箱密码,或者授权码。具体请参看各STMP服务商的设置说明</p>
			</el-form-item>
	<!-- 		<el-form-item label="注册启用邮箱">
				<el-switch v-model="form.regis_smtp_enable" active-value="1" inactive-value="0"></el-switch>
				<p class="notic">用户注册时使用邮箱验证</p>
			</el-form-item> -->
			<el-form-item label="测试接收的邮件地址">
				<div style="margin-top: 5px;width: 233px;">
					<el-input v-model="form.test_eamil" size="mini">
						<el-button slot="append" size="mini" @click="mailTest()" :loading="sendLoading">测试</el-button>
					</el-input>
				</div>
				<p class="notic">首次请先保存配置再测试</p>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="onSubmit" :loading="subLoading">确认提交</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import {
		mailTest,getConfigs,updateConfigs
	} from "@/utils/api";
	export default {
		data() {
			return {
				form: {},
				subLoading: false,
				sendLoading: false,
			};
		},
		created() {
			this.getConfigs();
		},
		methods: {
			getConfigs() {
				var that = this;
				getConfigs({inc_type: "smtp"}).then(function(res) {
					that.form = res.smtp;
				});
			},
			mailTest() {
				var that = this;
				var mailVo = {
					host: this.form.smtp_server,
					port: this.form.smtp_port,
					sender: this.form.smtp_user,
					sender_pwd: this.form.smtp_pwd,
					receiver: this.form.test_eamil
				};
				that.sendLoading = true
				mailTest(mailVo).then(function(res) {
					that.sendLoading = false
					if (res.status == 1) {
						that.$message.success("发送成功！");
					} else {
						that.$message.error(res.msg);
					}
				});
			},
			onSubmit() {
				var that = this;
				that.subLoading = true
				updateConfigs('smtp', that.form).then(function(res) {
					that.subLoading = false
					if (res.status == 1) {
						that.$message.success("保存成功");
					} else {
						that.$message.error("保存失败，原因:" + res.msg);
					}
				});
			}
		}
	};
</script>
<style scoped>
	>>>.el-input--mini .el-input__inner {
		width: 200px;
	}
</style>
